package com.cheng.controller;

import com.cheng.common.exception.CommonException;
import com.cheng.common.results.DataRslt;
import com.cheng.common.utils.IdUtil;
import com.cheng.data.vo.ReqPageInfoVO;
import com.cheng.data.vo.RespPageInfoVO;
import com.cheng.data.vo.RoleInfoVO;
import com.cheng.data.vo.TreeVO;
import com.cheng.operation.PermInfoOperation;
import com.cheng.operation.RoleInfoOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author: ChengJW
 * @date: 2021/11/15 23:26
 * @version: 1.0
 * @description:
 */
@Controller
public class RolesAdminController extends BaseController{

    private static final Logger log = LoggerFactory.getLogger(RolesAdminController.class);

    @Autowired
    private RoleInfoOperation roleInfoOperation;

    @Autowired
    private PermInfoOperation permInfoOperation;

    @RequestMapping("/systemDefend/rolesAdmin")
    public String rolesAdmin(){
        return "rolesAdmin";
    }

    @RequestMapping("/systemDefend/roleAdmin/addRoleInfo")
    public String addUserInfo(){
        return "addRoleInfo";
    }

    @RequestMapping("/systemDefend/roleAdmin/updateRoleInfo")
    public String updateUserInfo(){
        return "updateRoleInfo";
    }

    @RequestMapping("/systemDefend/roleAdmin/showRolePermInfo")
    public String showRolePermInfo(){
        return "showRolePermInfo";
    }

    /**
    * @author: ChengJW
    * @params: [pageInfoVO]
    * @return: com.cheng.common.results.DataRslt
    * @date: 2021/11/15
    * @description: 查询角色列表信息
    */
    @RequestMapping("/systemDefend/rolesAdmin/queryRoleList")
    @ResponseBody
    public DataRslt selectRoleInfoList(ReqPageInfoVO pageInfoVO) throws CommonException{

        pageInfoVO.setUserCode(getUrCode());
        RespPageInfoVO respPageInfoVO = roleInfoOperation.queryRoleInfoList(pageInfoVO);
        return tabSuccess(respPageInfoVO);
    }

    /**
    * @author: ChengJW
    * @params: [roId]
    * @return: com.cheng.common.results.DataRslt
    * @date: 2021/11/16
    * @description: 查询角色所有菜单权限
    */
    @RequestMapping("/systemDefend/roleAdmin/showAllRolePermInfo")
    @ResponseBody
    public DataRslt selectRolePermInfoList(String roId) throws CommonException{

        List<TreeVO> treeVOList = permInfoOperation.queryAllPermInfoList(roId,"02");
        return success(treeVOList);
    }

    /**
    * @author: ChengJW
    * @params: []
    * @return: com.cheng.common.results.DataRslt
    * @date: 2021/11/16
    * @description: 新增角色时初始化角色编号
    */
    @RequestMapping("/systemDefend/roleAdmin/initRoleId")
    @ResponseBody
    public DataRslt initRoleId() throws CommonException{
        return success(IdUtil.getRoleId());
    }

    /**
     * @author: ChengJW
     * @params: []
     * @return: com.cheng.common.results.DataRslt
     * @date: 2021/11/16
     * @description: 新增角色时初始化所属单位
     */
    @RequestMapping("/systemDefend/roleAdmin/initRoleCode")
    @ResponseBody
    public DataRslt initRoleCode() throws CommonException{
        return success(getUrCode());
    }

    /**
    * @author: ChengJW
    * @params: [roleInfoVO]
    * @return: com.cheng.common.results.DataRslt
    * @date: 2021/11/17
    * @description: 插入角色信息
    */
    @RequestMapping("/systemDefend/roleAdmin/insertRoleInfo")
    @ResponseBody
    public DataRslt insertRoleInfo(RoleInfoVO roleInfoVO) throws CommonException{

        roleInfoOperation.insertRoleInfo(roleInfoVO);
        return success();
    }

    /**
    * @author: ChengJW
    * @params: []
    * @return: com.cheng.common.results.DataRslt
    * @date: 2021/11/17
    * @description: 修改页面时初始化角色信息
    */
    @RequestMapping("/systemDefend/roleAdmin/initRoleInfo")
    @ResponseBody
    public DataRslt initRoleInfo(String roId) throws CommonException{
        return  success(roleInfoOperation.queryRoleInfoById(roId));
    }
    /**
     * @author: ChengJW
     * @params: []
     * @return: com.cheng.common.results.DataRslt
     * @date: 2021/11/17
     * @description: 修改角色信息
     */
    @RequestMapping("/systemDefend/roleAdmin/updateRole")
    @ResponseBody
    public DataRslt updateoleInfo(RoleInfoVO roleInfoVO) throws CommonException{

        roleInfoOperation.updateRoleInfo(roleInfoVO);
        return success();
    }

    /**
    * @author: ChengJW
    * @params: [roleInfoVO]
    * @return: com.cheng.common.results.DataRslt
    * @date: 2021/11/18
    * @description: 删除角色信息
    */
    @RequestMapping(value = "/systemDefend/roleAdmin/deleteRole",produces="application/json;charset=UTF-8")
    @ResponseBody
    public DataRslt deleteRoleInfo(RoleInfoVO roleInfoVO) throws CommonException{

        roleInfoOperation.deleteRoleInfo(roleInfoVO);
        return success();
    }
}
